package com.icss.ah.login.action;

import java.util.HashMap;
import java.util.List;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.icss.ah.base.action.BaseAction;
import com.icss.ah.base.bean.Json;
import com.icss.ah.login.bean.UserInfoBean;
/**
 * 用户菜单权限
 * @author csadchen
 * @date 2017-03-23
 */
@Controller
@Scope("prototype")
public class MenuRightAction extends BaseAction{

	private final Logger errlog = Logger.getLogger("E");
	private final Logger infolog = Logger.getLogger("I");
	
	private String userCode;			//用户账号
	private UserInfoBean userInfo;		//用户信息
	private String menuType;			//菜单类型
	private String resourceParent;		//上级资源菜单
	private String ifMain;				//是否首页获取快捷菜单
	private List menuList;				//权限菜单
	private String resourceUuid;		//资源菜单id
	private String resourceCode;		//资源菜单编码
	
	/**
	 * 获取用户菜单权限
	 */
	public void queryMenuList(){
		jsonText = new Json();
		try{
			userInfo = getUserInfo("");
			
			int isOwner = userInfo.getIsOwner(); 
			
			HashMap hm = new HashMap();
			hm.put("userCode", getUserCodeFromSession());
			hm.put("shopId", userInfo.getShopId());
			hm.put("corpId", userInfo.getCorpId());
			hm.put("applyStatus", userInfo.getApplyStatus());
			hm.put("registerStatus", userInfo.getRegisterStatus());
			hm.put("appId", appId);
			hm.put("menuType", menuType);
			hm.put("resourceParent", resourceParent);
			hm.put("isOwner", isOwner);
			hm.put("ifMain", ifMain);
			menuList = menuRightService.queryMenuList(hm);
			jsonText.setSuccess(true);
			jsonText.setObj(menuList);
		} catch (Exception e) {
			e.printStackTrace();
			jsonText.setSuccess(false);
			jsonText.setMsg(e.getMessage());
		}
		str2Resp(JSONObject.fromObject(jsonText).toString());
	}
	/**
	 * 设为快捷菜单
	 */
	public void setShortcut(){
		jsonText = new Json();
		request = getRequest();
		try{
			userInfo = getUserInfo("");
			
			HashMap hm = new HashMap();
			hm.put("userCode", getUserCodeFromSession());
			hm.put("shopId", userInfo.getShopId());
			hm.put("corpId", userInfo.getCorpId());
			hm.put("appId", appId);
			hm.put("resourceUuid", resourceUuid);
			String result = menuRightService.setShortcut(hm);
			String[] str = result.split(",");
			if(str[0].equals("1")){
				jsonText.setSuccess(true);
			} else if(str[0].equals("2")){
				jsonText.setSuccess(false);
				jsonText.setMsg(str[1]);
			} else {
				jsonText.setSuccess(false);
			}
		} catch (Exception e) {
			e.printStackTrace();
			jsonText.setSuccess(false);
			jsonText.setMsg(e.getMessage());
		}
		str2Resp(JSONObject.fromObject(jsonText).toString());
	}

	public String getMenuType() {
		return menuType;
	}

	public void setMenuType(String menuType) {
		this.menuType = menuType;
	}


	public List getMenuList() {
		return menuList;
	}

	public void setMenuList(List menuList) {
		this.menuList = menuList;
	}

	public String getResourceParent() {
		return resourceParent;
	}

	public void setResourceParent(String resourceParent) {
		this.resourceParent = resourceParent;
	}

	public String getIfMain() {
		return ifMain;
	}

	public void setIfMain(String ifMain) {
		this.ifMain = ifMain;
	}

	public String getResourceUuid() {
		return resourceUuid;
	}

	public void setResourceUuid(String resourceUuid) {
		this.resourceUuid = resourceUuid;
	}

	public String getResourceCode() {
		return resourceCode;
	}

	public void setResourceCode(String resourceCode) {
		this.resourceCode = resourceCode;
	}
}
